#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    int count = 2;
    arr[0] = 0;
    arr[1] = 1;
    for (int i = 2;; i++) {
        arr[i] = arr[i - 1] + arr[i - 2];
        count++;
        if (arr[i] > n) break;

    }

    int sum1 = arr[count - 1];

    int sum2 = arr[count - 2];

    if (sum1 - n > n - sum2) cout << n - sum2 << endl;
    else cout << sum1 - n;
    return 0;
}
